package com.project.im.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class JacksonConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        List<Module> modules = new ArrayList<>();
        SimpleModule baseModule = new SimpleModule();
        baseModule.addSerializer(Long.class, ToStringSerializer.instance);
        baseModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
        modules.add(baseModule);
        return build -> build.serializationInclusion(JsonInclude.Include.NON_NULL)
                .modules(modules);
    }
}
